package com.jxust.vhr.service.impl;

import cn.hutool.core.util.StrUtil;
import com.jxust.debate.pojo.Company;
import com.jxust.debate.util.CommonResult;
import com.jxust.debate.util.ResultEnum;
import com.jxust.vhr.dao.CompanyDao;
import com.jxust.vhr.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class CompanyServiceImpl implements CompanyService {

    @Autowired
    private CompanyDao companyDao;

    /**
     * 注册公司
     * @param company 公司信息
     * @return
     */
    @Override
    public CommonResult CompanyRegister(Company company) {
        CommonResult commonResult=new CommonResult();
        try {
            companyDao.insert(company);
        }catch (Exception e){
            commonResult.setResultEnum(ResultEnum.FAILURE);
        }
        commonResult.setResultEnum(ResultEnum.SUCCESS);
        return commonResult;
    }


    /**
     * 验证公司ID是否存在
     * @param cid 公司ID
     * @return
     */
    @Override
    public CommonResult VerifyCID(String cid) {
        CommonResult commonResult= new CommonResult();
        Company company=companyDao.selectById(cid);
        if(company!=null&& !StrUtil.hasEmpty(company.getCid())){
            commonResult.setResultEnum(ResultEnum.SUCCESS);
        }else {
            commonResult.setCode(ResultEnum.FAILURE.getCode());
            commonResult.setMessage("公司ID错误");
        }
        return commonResult;
    }
}
